package com.itheima.tlias.util;

import lombok.Data;

/**
 * 返回值工具类
 */
@Data
public class ResultUtil {
    private ResultUtil() {

    }

    private Integer code;
    private String msg;
    private Object data;

    /**
     * 默认成功方法
     *
     * @return resultUtil
     */
    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = "success";
        return resultUtil;
    }

    /**
     * 携带自定义成功信息的返回
     *
     * @param message 成功信息
     * @return resultUtil
     */
    public static ResultUtil success(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = message;
        return resultUtil;
    }

    public static ResultUtil success(String message,Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = message;
        resultUtil.data = data;
        return resultUtil;
    }

    /**
     * 携带数据的成功方法
     *
     * @param data
     * @return
     */
    public static ResultUtil success(Object data) {
        ResultUtil resultUtil = success();
        resultUtil.data = data;
        return resultUtil;
    }

    /**
     * 默认失败方法
     *
     * @return resultUtil
     */
    public static ResultUtil fail(String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = message;
        return resultUtil;
    }
}
